<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="renderer" content="webkit" />
<title>无标题文档</title>
<link href="__PUBLIC__/admin/sncss/css/style.css" rel="stylesheet" type="text/css" />
<link href="__PUBLIC__/admin/sncss/css/combo.select.css" rel="stylesheet" type="text/css" />

<!-- <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/simditor/styles/simditor.css" /> -->
</head>

<body>

	<div class="place">
	<span>位置：</span>
	<ul class="placeul">
	<li><a>首页</a></li>
	<li><a>订单管理</a></li>
	<li><a>模拟订单</a></li>
	</ul>
	</div>

	<div class="formbody">

	<div class="formtitle"><span>模拟订单</span></div>
<form id="formid" name="form1" method="post" action="{:U('/Home/False/add_false')}" onsubmit="return form1_submit();">
	<ul class="forminfo">
	<li>
		<div style="width: 86px;line-height: 34px;display: block;float: left;">音频</div>
		<div class="container" style="float: left;">
			<div id="container">
				<a class="btn" id="pickfiles" href="#" style="display: block; text-align: center;line-height: 36px;" >选择文件</a>
	<input id="audio" type="hidden" value="" name="audio" />
			</div>
		</div>
		<div style="clear: both;"></div>
	</li>
	<li>
	<div style="width: 86px;line-height: 34px;display: block;float: left;">自媒体</div>
	<div class="dowebok" style="float: left;">
	<select name="media" id="media" >
		<option value="">请选择</option>
		<?php foreach ($medialist as $key => $value) { ?>
		<option value="<?php echo $value['id'];?>"><?php echo $value['media_name'];?></option>
		<?php }?>
	</select>
	</div>
	</li>
	<li>
	<div style="width: 86px;line-height: 34px;display: block;float: left;">专辑</div>
	<div class="dowebok" style="float: left;">
	<select name="special" id="special" >
		<option value="0">不选择专辑</option>
	</select>
	</div>
	</li>
	<li>
	<div style="width: 86px;line-height: 34px;display: block;float: left;">类型</div>
	<div class="dowebok" style="float: left;">
	<select name="label" id="label" >
		<?php foreach ($labeldata as $key => $value) { ?>
		<option value="<?php echo $value['label_name'];?>"><?php echo $value['label_name'];?></option>
		<?php }?>
	</select>
	</div>
	</li>
	<!-- <li><label>性别</label>
		<label><input name="sex" type="radio" value="0" checked="checked"/>全部</label>
		<label><input name="sex" type="radio" value="1" />男</label>
		<label><input name="sex" type="radio" value="2" />女</label>
	</li> -->
	<li><label>链接</label><input name="user_url" id="user_url" type="text" class="lginput" value="" />
	<input type="button" id="get_url" class="btn" value="获取"/></li>
	<li><label>标题</label><input name="title" id="title" type="text" class="lginput" value="" /><i></i></li>
	<li><label>文章</label><textarea style="float: left;" name="article" id="article" onkeyup="cal_words()" ></textarea><i></i></li>
	<li><br>
	<label style="width: 120px;">总字数<i id="num">0</i>个</label>
	<!-- <label style="width: 120px;">预计用时<i id="ptime">0</i>分</label> -->
	<!-- <label style="width: 160px;">等级：<select name="level" id="level" class="newselect" onchange="change_level()" >
		<?php foreach ($leveldata as $key => $value) { ?>
		<option value="<?php echo $value['id'];?>"><?php echo $value['message'];?></option>
		<?php }?>
	</select>级</label> -->
	<!-- <label style="width: 220px;">预计花费<i id="cost">0</i>元<i id="discount_message"></i></label> -->
	</li>

	<input name="level" id="level" type="hidden" value="5" />
	<input name="sex" id="sex" type="hidden" value="0" />
	<input name="wordnumber" id="wordnumber" type="hidden" value="" />
	<input name="plan_time" id="plan_time" type="hidden" value="" />
	<input name="moneynumber" id="moneynumber" type="hidden" value="" /><!-- 原价 -->
	<input name="discount" id="discount" type="hidden" value="100" /><!-- 折扣 -->
	<input name="usemoney" id="usemoney" type="hidden" value="" /><!-- 实价 -->
	<?php foreach ($leveldata as $key => $value) { ?>
	<input id="use_money<?php echo $value['id'];?>" type="hidden" value="<?php echo $value['money'];?>" />
	<?php }?>
	<input id="use_money0" type="hidden" value="0" />
	<input id="is_collect" type="hidden" value="0" name="is_collect" />
	<input id="isvip" type="hidden" value="0" name="isvip" />
	<li></li>

	<li><label>&nbsp;</label><input type="submit" class="btn" value="模拟订单"/></li>
	</ul>
</form>

	</div>


</body>
<script src="__PUBLIC__/admin/Js/jquery-1.7.2.min.js"></script>
<script src="__PUBLIC__/layer/layer.js"></script>
<script src="__PUBLIC__/admin/Js/jquery.combo.select.js"></script>
<script type="text/javascript" src="__PUBLIC__/admin/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__PUBLIC__/admin/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/admin/ueditor/lang/zh-cn/zh-cn.js"></script>

<!-- <script src="__PUBLIC__/admin/simditor/jquery-1.10.2.js"></script> -->
<!-- <script type="text/javascript" src="__PUBLIC__/admin/simditor/scripts/module.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/admin/simditor/scripts/hotkeys.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/admin/simditor/scripts/uploader.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/admin/simditor/scripts/simditor.min.js"></script>
<script>
	var editor = new Simditor({textarea:$('#article')});
	editor.on('valuechanged', function(e, src){
		cal_words();
	})
//然后提交
function delHtmlTag(str)
{
str=str.replace(/<[^>]+>/g,"");//去掉所有的html标记
str=str.replace(/&nbsp;/ig, "");
return str;
}
</script> -->
<script type="text/javascript">
var editor = UE.getEditor('article',{    //content为要编辑的textarea的id
	initialFrameWidth: 800,   //初始化宽度
	initialFrameHeight: 200,   //初始化高度
});
editor.addListener('keyup',function(){
		cal_words();
 })
</script>
<script>
$(function() {
	$('#media').comboSelect();
	$('#special').comboSelect();
	$('#label').comboSelect();
});
</script>
<script type="text/javascript">
function form1_submit(){
	var audio= $('#audio').val();
	if(audio.length == 0){
		layer.tips('请上传音频', '#audio');return false;
	}
	var media= $('#media').val();
	if(media.length == 0){
		layer.tips('请选择自媒体', '#media');return false;
	}
	var label= $('#label').val();
	if(label.length == 0){
		layer.tips('请选择类型', '#label');return false;
	}
	var title= $('#title').val();
	if(title.length == 0){
		layer.tips('请填写标题', '#title');return false;
	}
	var article = UE.getEditor('article').getContentTxt();
	if(article.length == 0){
		layer.tips('请录入文章', '#article');return false;
	}
	var level=$('#level').val();
	if(level.length == 0){
		layer.tips('请选择等级', '#level');return false;
	}

}
//用word方式计算正文字数
function fnGetCpmisWords(str){
	sLen = 0;
	try{
		//先将回车换行符做特殊处理
		str = str.replace(/(\r\n+|\s+|　+)/g,"龘");
		//处理英文字符数字，连续字母、数字、英文符号视为一个单词
		str = str.replace(/[\x00-\xff]/,"m");
		//每个字母、数字、英文符号视为一个单词
		// str = str.replace(/[\x00-\xff]/g,"m");
		//合并字符m，连续字母、数字、英文符号视为一个单词
		str = str.replace(/m+/g,"*");
		//去掉回车换行符
		str = str.replace(/龘+/g,"");
		//返回字数
		sLen = str.length;
	}catch(e){

	}
	return sLen;
}
function change_level(){
	var last = $("#level").find("option:selected").text();
	if (last == "收藏主播") {
		$('#is_collect').val(1);
	}else{
		$('#is_collect').val(0);
	}
	cal_words();
}
function cal_words(){
//获取html内容
// var html = ue.getContent();
//获取纯文本内容
var ue = UE.getEditor('article');
var text = ue.getContentTxt();

	// var editor = new Simditor({textarea:$('#article')});
	// var text =  delHtmlTag(editor.getValue());

	// alert(text);
	var max_mun = 100;//字数设置，上线时改成100
	// var article= $('#article').val();
	var length = fnGetCpmisWords(text);
	// alert(length);
	document.getElementById("num").innerHTML = length;
	document.getElementById("wordnumber").value = length;
	var discount=$('#discount').val();
	var level=$('#level').val();
	var levelmoney=$('#use_money'+level).val();
	if (length < max_mun) {
	// document.getElementById("cost").innerHTML = Number(levelmoney*discount/100).toFixed(2);
	document.getElementById("moneynumber").value = Number(levelmoney).toFixed(2);
	document.getElementById("usemoney").value = Number(levelmoney*discount/100).toFixed(2);
	// alert(levelmoney);
	}else{
	var user_num = Math.round(length/max_mun);
	// document.getElementById("cost").innerHTML = Number(levelmoney*user_num*discount/100).toFixed(2);
	document.getElementById("moneynumber").value = Number(levelmoney*user_num).toFixed(2);
	document.getElementById("usemoney").value = Number(levelmoney*user_num*discount/100).toFixed(2);

	}
	var plantime = Math.ceil(length/max_mun);
	// document.getElementById("ptime").innerHTML = Number(plantime*15);
	document.getElementById("plan_time").value = Number(plantime*15);
	/*暂时写死每千字15分钟*/
}


</script>

<script type="text/javascript">
	$(document).ready(function(){
		$('#media').change(function(){
			var media_id = $(this).val();
			$.get("/Home/Order/media_ajax",{media_id:media_id},function(data){
				// alert(data.media.isvip);
				$("#level_option").remove();
				$('#is_collect').val(0);
				if(data.media.uuid != 0){
					$('#use_money0').val(data.member.level_money);
					var txt = '<option id="level_option" value="'+data.member.level_id+'" selected>收藏主播</option>';
					$('#is_collect').val(1);
					$("#level").append(txt);
				}else{
					$('#use_money0').val("0");
				}
				document.getElementById("discount").value = Number(100);
				if (data.media.discount_type == 0) {
					// document.getElementById("discount_message").innerHTML = "(无折扣)";
				}
				if (data.media.discount_type == 1) {
					// document.getElementById("discount_message").innerHTML = "(折扣未开始)";
				}
				if (data.media.discount_type == 2) {
					// document.getElementById("discount_message").innerHTML = "(折扣已结束)";
				}
				if (data.media.discount_type == 3) {
					document.getElementById("discount").value = Number(data.media.discount);
					// document.getElementById("discount_message").innerHTML = "("+Number(data.media.discount/10).toFixed(1)+"折)";
				}
				document.getElementById("isvip").value = data.media.isvip;
				cal_words();
				$(".special_option").remove();
				for (var i = 0; i < data.special.length; i++) {
					var option = '<option class="special_option" value="'+data.special[i].id+'" selected>'+data.special[i].specialname+'</option>';
					$("#special").append(option);
				}
				$('#special').comboSelect();
			},'json');
		});
	});
</script>
<script type="text/javascript">
	$(document).ready(function(){
		$('#get_url').click(function(){
			var user_url = $('#user_url').val();
			$.post("/Home/Order/getwebcontent",{user_url:user_url},function(data){
				// alert(data.title);
				$('#title').val(data.title);
				UE.getEditor('article').setContent(data.message);
				cal_words();
			},'json');
		});
	});
</script>
<script type="text/javascript" src='__PUBLIC__/admin/Js/plupload.full.min.js'></script>
<!-- qiniu.js依赖于Plupload，所以Plupload要在qiniu.js之前引用 -->
<script type="text/javascript" src="__PUBLIC__/admin/Js/qiniu.js"></script>
<script type="text/javascript">
	//===========================================================================================================================================
var ADMIN_URL = "<?php echo "http://".ADMIN_URL;?>"
	var uploader = Qiniu.uploader({
			runtimes: 'html5,flash,html4',
			browse_button: 'pickfiles',
			// HTML中重要的div的ID
			container: 'container',
			drop_element: 'container',
			max_file_size: '1000mb',
			dragdrop: true,
			chunk_size: '100mb',

			uptoken_url:ADMIN_URL+'home/Common/uptoken',

			domain: 'http://audio.qiniudn.com',
			get_new_uptoken: false,
			auto_start:true,
			log_level: 5,
			unique_names: false,
			save_key: false,
			init: {
					'FilesAdded': function(up, file) {


					},
					'BeforeUpload': function(up, file) {

					},
					'UploadProgress': function(up, file) {

					},
					'UploadComplete': function(up,file) {

							// console.log("我是七牛",this);

					},
					'FileUploaded': function(up, file, info) {
							// console.log('文件上传完成后！');
							var obj=$.parseJSON(info.response);
							var hash=obj.hash;
							var key=obj.key;
							var persistentId=obj.persistentId;
							$('#audio').val(key);

					},
					'Error': function(up, err, errTip) {
							console.log('上传文件 失败！')
					},
					'Key': function(up, file) {
							var key = "";
							key=randomWord(true,10,100)+file.name;
							return key
					}

			}
	});

	uploader.bind('FileUploaded', function() {
			alert('文件上传成功！');
	})


	//随机生成随机数
	function randomWord(randomFlag, min, max){
			var str = "",
					range = min,
					arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];

			// 随机产生
			if(randomFlag){
					range = Math.round(Math.random() * (max-min)) + min;
			}
			for(var i=0; i<range; i++){
					pos = Math.round(Math.random() * (arr.length-1));
					str += arr[pos];
			}
			return str;
	}
//=====================================================================================================================================
</script>
</html>
